#pragma once
#include <boost/smart_ptr.hpp>
#include <boost/asio.hpp>

#define MAX_TRANSACTIONS	(4096)


class LMContext;
class LMMaster
{
public:
	LMMaster(boost::shared_ptr<LMContext> config);
	virtual ~LMMaster();

	void login();
	bool isLoggedin();
	void run();

	struct  
	{
		CRITICAL_SECTION cs_work;
		uint32	algorithm;
		// block data
		uint32	version;
		uint32	height;
		uint32	nBits;
		uint32	timeBias;
		uint8	merkleRootOriginal[32]; // used to identify work
		uint8	prevBlockHash[32];
		uint8	target[32];
		uint8	targetShare[32];
		uint32  targetCompact;
		uint32  shareTargetCompact;
		// extra nonce info
		uint8	coinBase1[1024];
		uint8	coinBase2[1024];
		uint16	coinBase1Size;
		uint16	coinBase2Size;
		// transaction hashes
		uint8	txHash[32*MAX_TRANSACTIONS];
		uint32	txHashCount;
	}workDataSource;

protected:
	void xptMiner_getWorkFromXPTConnection();

protected:
	boost::shared_ptr<LMContext> _context;
	uint8 algorithmInited[32];
};